home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / m2posx10.zoo / m2posix.10 / test / tthread.mpp < prev   
Encoding:
Text File  |  1993-06-20  |  2.1 KB  |  95 lines

  1. MODULE tthread;
  2. __IMP_SWITCHES__
  3. #if (defined HM2) || (defined HM2_OLD)
  4. (*$E+ lokale Prozedur als Parameter *)
  5. #endif
  6. #ifdef HM2
  7. #ifdef __LONG_WHOLE__
  8. (*$!i+: Modul muss mit $i- uebersetzt werden! *)
  9. (*$!w+: Modul muss mit $w- uebersetzt werden! *)
  10. #else
  11. (*$!i-: Modul muss mit $i+ uebersetzt werden! *)
  12. (*$!w-: Modul muss mit $w+ uebersetzt werden! *)
  13. #endif
  14. #endif
  15.  
  16. VAL_INTRINSIC
  17. CAST_IMPORT
  18.  
  19. FROM PORTAB IMPORT
  20. (* TYPE *) UNSIGNEDWORD, ANYLONG, SIGNEDLONG;
  21.  
  22. FROM proc IMPORT
  23. (* TYPE *) WaitVal,
  24. (* PROC *) tfork, wait, WEXITSTATUS;
  25.  
  26. FROM InOut IMPORT
  27. (* PROC *) Read, WriteString, WriteInt, WriteLn;
  28.  
  29. (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
  30.  
  31. VAR
  32.   globalvar : INTEGER;
  33.   ch        : CHAR;
  34.  
  35. (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
  36.  
  37. PROCEDURE idle;
  38. VAR i : UNSIGNEDWORD;
  39. BEGIN
  40.  FOR i:=0 TO MAX(UNSIGNEDWORD) DO
  41.  END;
  42. END idle;
  43.  
  44. PROCEDURE thread1 (arg : ANYLONG): INTEGER;
  45. VAR i : INTEGER;
  46. BEGIN
  47.   globalvar := 42;
  48.   FOR i:=1 TO 3 DO
  49.     idle;
  50.     WriteString("``thread1'': "); WriteInt(INT(CAST(SIGNEDLONG,arg)), 0);
  51.     WriteLn;
  52.   END;
  53.   RETURN(11);
  54. END thread1;
  55.  
  56. PROCEDURE thread2 (arg : ANYLONG): INTEGER;
  57. VAR i : INTEGER;
  58. BEGIN
  59.   FOR i:=1 TO 3 DO
  60.     idle;
  61.     WriteString("``thread2'': "); WriteInt(INT(CAST(SIGNEDLONG,arg)), 0);
  62.     WriteLn;
  63.   END;
  64.   RETURN(22);
  65. END thread2;
  66.  
  67.  
  68. VAR pid, pid1, pid2 : INTEGER;
  69.     state           : WaitVal;
  70.  
  71. BEGIN
  72.   globalvar := 0;
  73.   WriteString("``main'': globalvar: "); WriteInt(globalvar, 0); WriteLn;
  74.  
  75.   pid1 := tfork(thread1, 111);
  76.   pid2 := tfork(thread2, 222);
  77.  
  78.   idle;
  79.  
  80.   WriteString("``main'': thread1-pid: "); WriteInt(pid1, 0); WriteLn;
  81.   WriteString("``main'': thread2-pid: "); WriteInt(pid2, 0); WriteLn;
  82.  
  83.   LOOP
  84.     pid := wait(state);
  85.     IF pid < 0 THEN EXIT; END;
  86.     WriteString("``main'': pid "); WriteInt(pid, 0);
  87.     WriteString(" returned: "); WriteInt(WEXITSTATUS(state), 0);
  88.     WriteLn;
  89.   END;
  90.  
  91.   WriteString("``main'': globalvar: "); WriteInt(globalvar, 0); WriteLn;
  92.  
  93.   Read(ch);
  94. END tthread.
  95.